﻿@{
    ViewBag.Title = "Config";
    Layout = "~/Views/Shared/_LayoutManager.cshtml";
}
<!-- BEGIN PAGE LEVEL STYLES -->
<link rel="stylesheet" type="text/css" href="/Content/Metronic-v4.1.0/theme/assets/global/plugins/jstree/dist/themes/default/style.min.css" />
<!-- END PAGE LEVEL STYLES -->
@*<h2>角色：HR经理</h2>*@
<div class="tab-pane">
    <div class="portlet box blue margin-bottom-0 ">
        <div class="portlet-title">
            <div class="caption">
                <i class="fa fa-gift"></i>角色配置
            </div>
            <div class="tools">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
            </div>
        </div>
        <div class="portlet-body form">
            <div class="form-body">
                <div id="tree_2" class="tree-demo">
                </div>
            </div>
            <div class="form-actions">
                <div class="row">
                    <div class="col-md-offset-3 col-md-9">
                        <input type="button" name="btnSave" class="btn green-meadow" value="保存" />
                        <button type="button" class="btn green-meadow" data-dismiss="modal" style="margin-left: 70px;">关闭</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- BEGIN PAGE LEVEL SCRIPTS -->
<script src="/Content/Metronic-v4.1.0/theme/assets/global/plugins/jstree/dist/jstree.min.js"></script>
<!-- END PAGE LEVEL SCRIPTS -->
<script src="/Content/Metronic-v4.1.0/theme/assets/admin/pages/scripts/ui-tree.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function () {
        var userid = '@ViewBag.UserId';//"c7ed24b7-b2be-4fac-8954-bca09efdecc5";
        $.ajax({
            type: "post",
            url: "/Base_UserRole/GetRole",
            data: { primarykeys: userid },
            dataType: "json",
            success: function (data) {
                $('#tree_2').jstree(
                    {
                        'plugins': ["checkbox", "types"], //"wholerow",
                        'core': {
                            "themes": {
                                "responsive": false
                            },
                            'data': data
                        },
                        "types": {
                            "default": {
                                "icon": "fa fa-folder icon-state-warning icon-lg"
                            },
                            "file": {
                                "icon": "fa fa-file icon-state-warning icon-lg"
                            }
                        }
                    });
            },
            error: function (mes) {
                Command: toastr['error'](mes.responseText, "Message Notifications");
            }
        });

        //新建按钮事件
        $("input[name='btnSave']").click(function () {
           
            var $select = $(".jstree-clicked");
            var roleids = [];

            $select.each(function (index) {
                roleids.push($($select.get(index)).attr("role_id"));
            });
           
            //发送后台删除
            var selectData = { primarykeys: userid, roleid: roleids.toString() };
            var deleteUrl = "@Url.Action("EditRole", "Base_UserRole")";
            Metronic.startPageLoading();
            $.ajax({
                type: "post",
                url: deleteUrl,
                data: selectData,
                dataType: "json",
                success: function (data) {
                    Command: toastr['success'](data, "提示");
                    //$("li .active").children().click();
                    Metronic.stopPageLoading();
                }, error: function (data) {
                    Command: toastr['error'](data.statusText, "提示");
                    Metronic.stopPageLoading();
                }
            });
        });

    });
</script>

